package variable

import (
	"clientDemo/service/modulemgr"
	"github.com/ian-kent/go-log/log"
)

var Name = "variable-mod"

type IVariableModule interface {
	modulemgr.IModule
	GetVariable(id int) (IVariable, error)
	CreatVariable(id int, Type int, value interface{}) (IVariable, error)
	UpdateVariable(id int, Type int, value interface{}) (IVariable, error)
}

type IVariable interface {
	GetId() uint32
	GetValue() (interface{}, error)
	SetValue(interface{}) error
	GetType() Type_Variable
	SetType(t Type_Variable)
}

type Type_Variable uint32

const (
	Type_Variable_Int    Type_Variable = 1
	Type_Variable_String Type_Variable = 2
	Type_Variable_Float  Type_Variable = 3
	Type_Variable_Bool   Type_Variable = 4
	Type_Variable_Object Type_Variable = 5
	Type_Variable_Array  Type_Variable = 6
	Type_Variable_Map    Type_Variable = 7
	Type_Variable_Timer  Type_Variable = 8
)

type CreateCb func(id int, Type int, value interface{}) (IVariable, error)

var VariableCreatFuncMap = map[Type_Variable]CreateCb{}

func RegeditCreatVariableFunc(t Type_Variable, fn CreateCb) {
	_, ok := VariableCreatFuncMap[t]
	if ok == false {
		VariableCreatFuncMap[t] = fn
	} else {
		log.Error("VariableCreatFuncMap has regedit type %d", t)
	}
}
func GetCreatVariableFunc(t Type_Variable) CreateCb {
	return VariableCreatFuncMap[t]
}
